const {ccclass, property} = cc._decorator;

enum Triggle {
    START,
    ENABLE
}

enum SoundType {
    BGM,
    SOUND_EFFECT
}

@ccclass
export default class NewClass extends cc.Component {

    @property({type: cc.AudioClip})
    sound: cc.AudioClip = null;

    @property({type : cc.Enum(SoundType)})
    soundType : SoundType = SoundType.SOUND_EFFECT;

    @property({type : cc.Enum(Triggle)})
    triggleOn: Triggle = Triggle.ENABLE;

    @property
    delay : number = 0;

    onEnable(){
        // if(this.triggleOn == Triggle.ENABLE) this._playSound();
    }

    start () {
        // if(this.triggleOn == Triggle.START) this._playSound();
    }

    _playSound(){
        if(isSound){
            this.scheduleOnce(() => {
                if(this.soundType == SoundType.BGM){
                    cc.audioEngine.playMusic(this.sound, true);
                }
    
                if(this.soundType == SoundType.SOUND_EFFECT){
                    cc.audioEngine.playEffect(this.sound, false);
                }
            }, this.delay);
        }
    }
}
